import { computed, observable } from 'mobx';
import Axios from 'axios';
import Jsonp from 'jsonp';

class Form {
  @observable attributeGroupList = [];
  @observable dictList = [];
  @observable APL_RD_ORG = [];
  @observable BU = [];
  @observable SELF_OR_OUTSIDE = [];
  @observable SALES_BU = [];
  @observable PRODECE_ORG = [];
  @observable suggest = [];

  getSchemeAttrList = () => {
    Axios.post('/api?schemeAttrList', {
      apiName: 'schemeAttrList'
    })
      .then(response => {
        // console.log(response.data.data)
        this.attributeGroupList = response.data.data.content.tagList[0].attributeGroupList;
      })
      .catch(error => {
        console.log(error);
      });
  }

  getDictList = () => {
    Axios.post('/api?getDictList', {
      apiName: 'getDictList'
    })
      .then(response => {
        this.dictList = response.data;
        for (let key in response.data) {
          if (this[key]) {
            this[key] = response.data[key]
          }
        }
        console.log(response.data)
      })
      .catch(error => {
        console.log(error);
      });
  }

  getSuggest = (str) => {
    this.suggest = [];
    return new Promise((resolve) => {
      Jsonp(`https://suggest.taobao.com/sug?q=${str}`, null, (err, data) => {
        if (!err) {
          console.log('jsonp', data)
          resolve(data.result)
        }
      })
    }).then(res => {
      this.suggest = res;
    })
  }

  @computed get fullName() {
    return this.name + ' Chan';
  }
}

export default new Form();


/**
 * 1. 13 19:17
 * 2. 13 19:56
 * 3. 13 20:15
 * 4. 14 19:05
 * 5. 13 19:10
 * 6. 14 19:47
 */